from PySide2.QtWidgets import *

from api.api_project import create_idrs_dict
from api.api_view import ThCreateReview
from qttab.qtpage import TablePage
from qttab.qttable import DFTable
from qttab.qtwgt import show_msg

from view.table_col_list import idrs_col_model_list

tb_name = "idrs_doc"


class TableIDRS(DFTable):
    def __init__(self):
        super().__init__(tb_name, idrs_col_model_list, merge_key_col_name="doc_channel")

        self.need_merge_col_name_list = ["title", "idrs_channel", "comment", "comment", "sys_attachment", "date_draft",
                                         "status", "assister"]
        self.reset_data()

    """
    idrs.title,
    idrs.channel as idrs_channel, 
    idrs.comment, 
    idrs.sys_attachment, 
    idrs.status, 
    idrs.date_draft, 
    idrs.url as url, 
    idrs.assister, 
    idrs.file_channel, 
    """

    def change_dict_to_db(self):
        pass


class ViewIdrs(TablePage):
    def __init__(self):
        super().__init__("tab_idrs", TableIDRS(), tb_name)
        self.btn_delete_select = QPushButton("删除")
        self.btn_delete_select.clicked.connect(self.delete_select)

        self.btn_create_idrs_flow = QPushButton("保存并发起流程")
        self.btn_create_idrs_flow.clicked.connect(self.create_idrs_flow)
        self.btn_brush = QPushButton("刷新信息")
        self.btn_brush.clicked.connect(self.qtable.reset_data)
        self.left_tool_list = [self.btn_create_idrs_flow,self.btn_brush,self.btn_delete_select]
        self.init_tool_bar()
        self.th_flow = ThCreateReview([],review_type="idrs")

    def delete_select(self):
        print("触发删除")
        pass

    def update_doc_view(self, condition):

        show_msg(f"已完成查询，共查新2条", self.message_label)


  def create_idrs_flow(self):
        if self.table.change_dic:
            self.save_drcs()

        dict_list = create_idrs_dict(self.table.datas)
        if dict_list:
            self.th_flow.datas = dict_list
            self.th_flow.signal_send.connect(self.create_flow_result)
            self.th_flow.start()
        else:
            QMessageBox.information(self, f"创建{tb_name}流程信息", f"没有需创建{tb_name}流程的文件")